package org.myblog.myblogserver.generator.template;

import org.apache.velocity.app.Velocity;
import java.util.Properties;

public class TemplateInitializer {

    public static void init() {
        Properties properties=new Properties();
        // 设置加载模板的方式，这里从classpath下加载

        properties.setProperty("resource.loader","classpath");
        properties.setProperty("classpath.resource.loader.class","org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        properties.setProperty("classpath.resource.loader.cache","false"); // 关闭类路径资源加载器缓存，方便测试时及时加载最新模板
        properties.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
        properties.setProperty("runtime.strict_mode","false");

        try{
            Velocity.init(properties);
        } catch (Exception e){
            throw new RuntimeException("初始化Velocity引擎失败", e);
        }

    }
}
